package com.myk.game.heroscuffle.heroes;

import com.myk.game.heroscuffle.game.Attacked;
import com.myk.game.heroscuffle.game.Element;
import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.Sign;
import com.myk.game.heroscuffle.game.Skill;
import com.myk.game.heroscuffle.skills.Skill_GanLin;
import com.myk.game.heroscuffle.skills.Skill_JuLang;
import com.myk.game.heroscuffle.utils.RdmPropUtil;
import com.myk.game.heroscuffle.utils.WeighterTask;

public class Hero_ShuiQing extends Hero {

    public Hero_ShuiQing() {
        super("水清", "攻击敌人后有几率使目标眩晕跳过本回合，被攻击后有几率恢复受到的一半伤害。",
                Element.ICE,
                1180, 145, 42,
                new Skill_GanLin(), new Skill_JuLang());
    }

    @Override
    public void onAutoSelectAction() {
        Skill julang = getUsableSkill(Skill_JuLang.class); //获取可用的雪隐技能
        Skill ganlin = getUsableSkill(Skill_GanLin.class); //获取可用的雪隐技能
        boolean isLowHp = hp < (HP * 2 / 3f); //是否血量有消耗

        Runnable useJuLang = () -> useSkill(julang); //使用主动技巨浪
        Runnable useGanLin = () -> useSkill(ganlin); //使用主动技甘霖
        Runnable doAttack = () -> { //进行普通攻击
            Attacked attacked = autoSelectAttacked();
            attacked.setReason("召唤漩涡冲向");
            doAttackActionStart(attacked);
        };

        if (julang != null) { //可以用巨浪
            if (ganlin != null) {
                if (isLowHp) {
                    RdmPropUtil.lotteryExecute(new WeighterTask(3, useJuLang), new WeighterTask(4, useGanLin), new WeighterTask(5, doAttack));
                }
                else {
                    RdmPropUtil.lotteryExecute(new WeighterTask(3, useJuLang), new WeighterTask(4, useGanLin), new WeighterTask(7, doAttack));
                }
            }
            else {
                RdmPropUtil.lotteryExecute(new WeighterTask(3, useJuLang), new WeighterTask(8, doAttack));
            }
        }
        else {//不能用巨浪
            if (ganlin != null) {
                if (isLowHp) {
                    RdmPropUtil.lotteryExecute(new WeighterTask(4, useGanLin), new WeighterTask(5, doAttack));
                }
                else {
                    RdmPropUtil.lotteryExecute(new WeighterTask(3, useGanLin), new WeighterTask(5, doAttack));
                }
            }
            else {
                doAttack.run(); //没有技能可用只能默认普攻行为
            }
        }
    }

    @Override
    public void onAcceptPlayerAttackAction(Attacked preAttacked) {
        if (RdmPropUtil.bingo(state.exactRate) || game.pool.getAliveCount() == 2) {
            Hero attacked = preAttacked.getTarget(); //系统默认选中的目标
            this.doAttackActionStart(new Attacked(attacked, "召唤漩涡冲向"));
        }
        else {
            Hero attacked = game.pool.getAnyoneAliveHero(this, preAttacked.getTarget()); //另外选一个目标
            this.doAttackActionStart(new Attacked(attacked, "召唤出失控的漩涡冲向"));
        }
    }

    @Override
    public void onAfterDoAttack(Hero attacked, int damage, boolean isToDeath) {
        if (!isToDeath && !attacked.state.isActioned) {
            if (RdmPropUtil.bingo(1, 3)) {
                game.ui.sleepShortly();
                game.ui.printMsg(attacked.getObviousName() + "被漩涡击晕，跳过该回合。");
                attacked.setActioned();
            }
        }
    }

    @Override
    public void onAfterSufferDamage(Hero attacker, Skill sourceSkill, Sign sourceSign, int damage) {
        //被普通攻击时，有几率恢复部分受到的伤害
        if (attacker != null) {
            if (RdmPropUtil.bingo(1, 2)) {
                int hpAdd = damage / 2;
                hp += hpAdd;
                game.ui.printMsg("清水回流" + getObviousName() + "hp恢复" + hpAdd + "点，");
                game.ui.sleepShortly();
            }
        }
    }
}
